package com.zb.sannuo.thereport.controller;

import com.zb.sannuo.common.domain.search.JCFrequency;
import com.zb.sannuo.common.domain.vo.ReportVo;
import com.zb.sannuo.common.result.Result;
import com.zb.sannuo.common.result.ResultCode;
import com.zb.sannuo.thereport.service.XfzDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/reports")
@Api(value = "报表管理模块",description = "消费者数据图标")
@CrossOrigin
public class XfzDataController {

    @Resource
    private XfzDataService xfzDataServiceImpl;

    @ApiOperation(value = "查询检测时段人次分布",notes = "查询检测时段人次分布",httpMethod = "GET")
    @RequestMapping(value = "jcRc",method = RequestMethod.GET)
    public Result findXfzData(ReportVo reportVo) throws Exception{

        List<JCFrequency> xfzData = xfzDataServiceImpl.findXfzData(reportVo);
        Integer[] weeks = new Integer[7];
        JCFrequency jcFrequency = null;
        for (int i = 1; i <= 7; i++){
            for (JCFrequency xfzDatum : xfzData) {
                if (xfzDatum.getWeeks()==i){
                    weeks[i-1] = xfzDatum.getNumber();
                    System.out.println("星期:" + i + "---检测人次:" +weeks[i-1]);
                }
            }
        }

        HashMap<String, Integer[]> map = new HashMap<>();
        map.put("weeks",weeks);
        return Result.ok(ResultCode.SUCCESS,map);
    }

    @ApiOperation(value = "结果分析",notes = "结果分析",httpMethod = "GET")
    @RequestMapping(value = "jgFx",method = RequestMethod.GET)
    public Result findJgFx(String searchParams) throws Exception{

        List<JCFrequency> jgFx = xfzDataServiceImpl.findJgFx(searchParams);
        for (JCFrequency fx : jgFx) {
            System.out.println(fx);
        }
        return Result.ok(ResultCode.SUCCESS,jgFx);
    }
}
